package com.by.service.Impl;


import com.by.bean.Products;
import com.by.common.bean.PageBean;
import com.by.common.crud.BaseServiceImpl;
import com.by.mapper.ImgMapper;
import com.by.mapper.ProductMapper;
import com.by.query.ProductImg;
import com.by.query.ProductQuery;
import com.by.service.ProductService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;


/**
 * @author Hzy
 * @version 1.0
 * @date 2025/2/18  19:49
 * @description
 * @since jdk11
 */
@Service
public class ProductServiceImpl extends BaseServiceImpl<Products, ProductMapper> implements ProductService {

    @Autowired
    ImgMapper imgMapper;
    @Autowired
    ProductMapper productMapper;

    @Override
    public PageBean queryByMap(ProductQuery query) {
        PageHelper.startPage(query.getPage(), query.getPageSize());
        List list = productMapper.queryByMap(query);
        PageInfo info = new PageInfo(list);
        return new PageBean(query.getPage(), query.getPageSize(), info.getTotal(), list);
    }

    @Override
    public Products get(String id) {
       Products products = productMapper.get(id);

        return products;
    }

    @Transactional
    @Override
    public int save(Products product) {
        //pduc
        int rs=super.save(product);
        //banbner
        imgMapper.batchSave(product.getId(),product.getBanner());
        return 1;
    }


}
